package m.html.form;

import m.html.element.Element;
import m.html.element.other.IElement;
import m.system.util.GenerateID;
import m.system.util.StringUtil;

import java.util.*;

public class LoadPage implements IForm{
    private final String divId;
    private String test;
    private String mounted;
    private final FormEvent event;
    @Override
    public IElement getElement(boolean hasBack) {
        Element tag=Element.tag("div").A("id",divId);
        if(StringUtil.notSpace(test)) tag.A("v-show",test);
        return tag;
    }
    @Override
    public boolean isShowHead() {
        return true;
    }
    public LoadPage(String methodName,String url){
        this(methodName,url,"{}");
    }
    public LoadPage(String methodName,String url,String param){
        this.divId="loadPage_"+GenerateID.tempKey();
        this.event=FormEvent.custom(methodName,
                "this.loadPage(\""+divId+"\",\""+url+"\","+param+",function(pv,v3){}.bind(this));");
    }
    /**
     * 设置表达式 显示或隐藏
     */
    public LoadPage setTest(String ifTest){
        this.test=ifTest;
        return this;
    }

    @Override
    public String getMounted() {
        return mounted;
    }

    /**
     * 设置页面加载后执行的js
     */
    public LoadPage setMounted(String mounted) {
        this.mounted = mounted;
        return this;
    }

    @Override
    public Map<String, Object> getData() {
        return new HashMap<>();
    }

    @Override
    public List<FormEvent> getMethods() {
        return Collections.singletonList(this.event);
    }

    @Override
    public Map<String, String> getWatch() {
        return new HashMap<>();
    }
}
